import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vuejsx from "@vitejs/plugin-vue-jsx";
import styleImport from "vite-plugin-style-import";
import path from "path";
// https://vitejs.dev/config/
export default defineConfig({
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
    },
  },
  base: "./",
  server: {
    host: "0.0.0.0",
    port: 3000,
    proxy: {
      "/api": {
        // 颜家阳
        // target: "http://192.167.5.152:8095/",
        // 占海维
        // target: "http://192.167.5.43:8095/",
        // 陈静
        // target: "http://192.167.5.181:8095/",
        // 测试环境
        target: "http://dhdxfh5.test.ztesa.work/",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ""),
      },
      "/amap": {
        // target:'http://192.167.5.7:8181/',
        target: "http://restapi.amap.com/v3",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/amap/, ""),
      },
    },
  },
  plugins: [
    vue(),
    vuejsx({ enableObjectSlots: true }),
    styleImport({
      libs: [
        {
          libraryName: "vant",
          esModule: true,
          resolveStyle: (name) => {
            return `../../vant/es/${name}/style`;
          },
        },
      ],
    }),
  ],
  css: {
    modules: {
      generateScopedName: "[path]_[local]_[hash:base64:5]",
      hashPrefix: "prefix",
    },
    preprocessorOptions: {
      less: {
        modifyVars: {
          hack: `true; @import (reference) "${path.resolve(
            "src/theme/variable.less"
          )}";`,
        },
        javascriptEnabled: true,
      },
    },
  },
});
